package de.grosjohann.android.feuerwehr;

import android.content.Context;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import de.grosjohann.android.feuerwehr.type.FMSStatusType;
import de.grosjohann.android.feuerwehr.type.FireIndexType;
import de.grosjohann.android.feuerwehr.type.WeatherWarningType;

public class NotifyPrefsActivity
  extends PreferenceActivity {

  public final static String SPEC_NOTIFY = "feuerwehr.specialNotification";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.layout.notifyprefs);

    Context ctx = getApplicationContext();
    Bundle extras = getIntent().getExtras();

    Object obj = extras.getSerializable(SPEC_NOTIFY);

    getPreferenceScreen().getPreference(0).setSelectable(false);
    if (obj instanceof FMSStatusType) {
      // Checkboxen fuer die FMS-Benarichtigung generieren
      getPreferenceScreen().getPreference(0).setTitle(R.string.lblFMSNotifications);
      getPreferenceScreen().getPreference(0).setSummary(R.string.sumFMSNotifications);

      for (FMSStatusType type : FMSStatusType.values()) {
        CheckBoxPreference cb = new CheckBoxPreference(ctx);

        cb.setKey(type.name());
        cb.setDefaultValue(true);
        cb.setSummary("Status " + type.getStatus());
        cb.setTitle(type.getResId());
        getPreferenceScreen().addPreference(cb);
      }
    } else if (obj instanceof WeatherWarningType) {
      // Checkboxen fuer die Wetter-Benarichtigung generieren
      getPreferenceScreen().getPreference(0).setTitle(R.string.lblWeatherNotifications);
      getPreferenceScreen().getPreference(0).setSummary(R.string.sumWeatherNotifications);

      for (WeatherWarningType type : WeatherWarningType.values()) {

        CheckBoxPreference cb = new CheckBoxPreference(ctx);
        cb.setKey(type.name());
        cb.setDefaultValue(true);
        cb.setTitle(type.getResId());
        getPreferenceScreen().addPreference(cb);
      }
    } else if (obj instanceof FireIndexType) {
      // Checkboxen fuer die Waldbrandindex-Benarichtigung generieren
      getPreferenceScreen().getPreference(0).setTitle(R.string.lblFireIndexNotifications);
      getPreferenceScreen().getPreference(0).setSummary(R.string.sumFireIndexNotifications);

      for (FireIndexType type : FireIndexType.values()) {

        CheckBoxPreference cb = new CheckBoxPreference(ctx);
        cb.setKey(type.name());
        cb.setDefaultValue(true);
        cb.setTitle(type.getResId());
        getPreferenceScreen().addPreference(cb);
      }
    }

  }
}